//
//  UIView+Box.m
//  Das
//
//  Created by yingzhi on 14-8-7.
//  Copyright (c) 2014年 yingzhi. All rights reserved.
//

#import "UIView+Box.h"

#define kLineBorder 0.25
@implementation UIView (Box)

- (void)fillet
{
    [self fillet:6.0f];
}

- (void)fillet:(CGFloat)radius
{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = radius;
}

- (void)insertDividingLine
{
    [self insertDividingLine:[UIColor clearColor] LineColor:HexRGB(0xd9d9d9)];
}

- (void)insertGroundLine
{
    [self insertGroundLine:[UIColor clearColor] LineColor:HexRGB(0Xcccccc)];
}

- (void)insertDividingLine:(UIColor*)back LineColor:(UIColor*)line
{
    [self insertDividingLine:back LineColor:line BorderWidth:kLineBorder Azimuth:DLA_BOTTOM];
}

- (void)insertGroundLine:(UIColor*)back LineColor:(UIColor*)line
{
    [self insertGroundLine:back LineColor:line BorderWidth:kLineBorder];
}

- (void)insertDividingLine:(DividingLineAzimuth) azimuth
{
    [self insertDividingLine:[UIColor clearColor] LineColor:HexRGB(0Xcccccc) BorderWidth:kLineBorder Azimuth:azimuth];
}

- (void)insertDividingLine:(UIColor*)back LineColor:(UIColor*)line BorderWidth:(CGFloat)width Azimuth:(DividingLineAzimuth) azimuth
{
    CGFloat top = azimuth == DLA_TOP?0:self.bounds.size.height-1;
    
    CALayer *layer = [CALayer new];
    layer.frame = CGRectMake(0, top, self.bounds.size.width, 1);
    layer.borderWidth = width;
    layer.borderColor = line.CGColor;
    layer.backgroundColor = back.CGColor;
    [self.layer addSublayer:layer];
}

- (void)insertGroundLine:(UIColor*)back LineColor:(UIColor*)line BorderWidth:(CGFloat)width
{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 6.0;
    self.layer.borderWidth = width;
    self.layer.borderColor = line.CGColor;
    self.layer.backgroundColor = back.CGColor;
}

@end
